<template>
  <div class="tags">
    <el-tag v-for="(item, index) in items" :key="item.label" :closable="item.name !== 'home'" :effect="$route.path === item.path ? 'dark' : 'plain'" @click="changeMenu(item)" @close="close(item, index)">
      {{ item.label }}
    </el-tag>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  data() {
    return {}
  },
  computed: {
    ...mapState({
      items: state => state.tab.tabList
    })
  },
  methods: {
    ...mapMutations(['removeTagList']),
    changeMenu(item) {
      // console.log(item.push);
      this.$router.push(item.path)
    },
    close(item, index) {
      this.removeTagList(item)
      const length = this.items.length
      if (item.path !== this.$route.path) {
        return
      }
      if (index === length) {
        this.$router.push(this.items[index - 1].path)
      } else {
        this.$router.push(this.items[index].path)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.tags {
  padding: 20px;
  .el-tag {
    margin-right: 15px;
    cursor: pointer;
  }
}
</style>
